<?php
namespace app\wechat\controller;

use app\wechat\logic\App;
use app\wechat\logic\Msg;
use think\Db;

class Wechat
{
    public function index($id)
    {
        $app = new App($id);
        $wApp = $app->getApp();
        $wApp->server->push(function($message) use ($wApp){
            return Msg::handle($message,$wApp);
        });
        
        $response = $wApp->server->serve();
        $response->send();
    }
    
    public function accessToken($id)
    {
        $app = new App($id);
        $token = $app->getAccessToken();
        return json($token);
    }
}
